package containerlogistik.implementation;

import static com.google.common.base.Preconditions.*;
import containerlogistik.interfaces.StowageLocation;
import java.util.Objects;
/**
 * 
 * @param Implementation von StowageLocation
 *
 */
public class StowageLocationImpl implements StowageLocation {
    
    final int bay;
    final int row;
    final int tier;
    
    private StowageLocationImpl(int bay, int row, int tier) {
        checkArgument(bay >= 0 && row >= 0 || tier >= 0, "Bay, Row and Tier must be positive.");
        this.bay = bay;
        this.row = row;
        this.tier = tier;
    }
    
    static StowageLocation valueOf(int bay, int row, int tier) {
        return new StowageLocationImpl(bay, row, tier);
    }
    
    @Override
    public int bay() {
        return this.bay;
    }

    @Override
    public int row() {
        return this.row;
    }

    @Override
    public int tier() {
        return this.tier;
    }

    @Override
    public int capacity() {
        return this.bay() * this.row() * this.tier();
    }
    
    /* Predicates */

    @Override
    public boolean isNull() {
        return false;
    }

    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final StowageLocationImpl other = (StowageLocationImpl) obj;
        if (this.bay != other.bay) {
            return false;
        }
        if (this.row != other.row) {
            return false;
        }
        if (this.tier != other.tier) {
            return false;
        }
        return true;
    }

    public int hashCode() {
        return Objects.hash(this.bay(), this.row(), this.tier());
    }
    
}
